13 vector
<bool> forbidden(10000, false);
14 vector
<bool> visited(10000, false);
18 for (int i
=0; i
<4; ++i
){
19 int x
; scanf("%d", &x
);
20 start
= (start
* 10) + x
;
24 for (int i
=0; i
<4; ++i
){
25 int x
; scanf("%d", &x
);
33 for (int i
=0; i
<4; ++i
){
34 int x
; scanf("%d", &x
);
40 queue
<pair
<int, int> > q
;
42 q
.push(make_pair(start
, 0));
44 int node
= q
.front().first
;
45 int dist
= q
.front().second
;
47 if (forbidden
[node
] || visited
[node
]){
54 //cout << "visited["<<node<<"] = " << (visited[node]?"true":"false") << endl;
56 for (int i
=1; i
<=4; ++i
){
57 int pow10
= 1; for (int j
=1; j
<=i
; ++j
) pow10
*= 10;
58 int digit
= (node
% pow10
)* 10/pow10
;
60 int v
= node
- digit
* pow10
/10;
61 //cout << "digit es: " << digit << endl;
62 //cout << "node es: " << node << endl;
63 //cout << "v es: " << v << endl << endl;
64 int x
= v
+ pow10
/10 * ((digit
+1)%10);
65 int y
= v
+ pow10
/10 * ((digit
+9)%10);
67 //cout << "Los vecinos:" << endl;
68 //cout << x << endl << y << endl;
71 // if (forbidden[x] == false && visited[x] == false){
72 q
.push(make_pair(x
, dist
+ 1));
74 //if (!forbidden[y] && !visited[y]){
75 q
.push(make_pair(y
, dist
+ 1));
80 cout
<< answer
<< endl
;